# 作者：一只牛吗
# 2025 年01月 21日 03时 00分 04秒
# 1278599690@qq.com
def use_dict_base():
    '''
    字典的基本操作
    :return:dict1
    '''
    dict1 = {'name': 'Alice', 'age': 20, 'city': 'Beijing'}
    # print(dict1.pop('age'))
    # del dict1['age']
    # print(dict1)

    dict1.update({'age': 21, 'city': 'Shanghai'})
    print(dict1)

    for k in dict1:
        print(k, dict1[k])
    return dict1


def use_dict_iter():
    '''
    字典遍历
    :return:
    '''
    dict1 = {'name': 'Alice', 'age': 20, 'city': 'Beijing'}
    tuple1 = dict1.items()
    print(tuple1)
    for k, v in dict1.items():
        print(k, v)

    list1 = [[k, v] for k, v in dict1.items()]
    print(list1)

    for k, v in list1:
        print(k, v)


if __name__ == '__main__':
    # use_dict_base()
    use_dict_iter()
    k, v = 1, 2
    print(k, v)
    dict1 = {'name': 2}
    dict1.setdefault('nae' , 1)
    print(dict1)